home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 5035 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.2 KB

  1. Path: news.mcs.net!mdp
  2. From: mdp@mika-sys.com (Michael D. Perry)
  3. Newsgroups: comp.lang.c
  4. Subject: Save My Sanity, Please Help; was Bitwise Operators, Help with please!
  5. Date: Mon, 12 Feb 96 01:03:04 GMT
  6. Organization: MIKA Systems
  7. Message-ID: <4fm3k8$nck_001@pr.mcs.net>
  8. References: <4fjaju$i1o_001@pr.mcs.net>
  9. NNTP-Posting-Host: mdp.pr.mcs.net
  10. X-Newsreader: News Xpress Version 1.0 Beta #4
  11.  
  12. I posted the below quoted post last night and have continued to 
  13. try and solve this problem with no luck - this is driving me nuts 
  14. that I cannot figure this out.  Please help.
  15.  
  16. Thanks in advance.
  17.  
  18. Mike
  19.  
  20. In article <4fjaju$i1o_001@pr.mcs.net>,
  21.    mdp@mika-sys.com (Michael D. Perry) wrote:
  22. >Hello All;
  23. >
  24. >I am trying to teach myself 'C' programming from a book which 
  25. >perhaps is not explaining the Bitwise Operators as well as I 
  26. >would desire in order to understand them.
  27. >
  28. >After going through a few examples the book is having me write a 
  29. >program that will pack som data and then unpak using bitwise 
  30. >operators.  I have the packing down OK and can print the bits 
  31. but 
  32. >am just not getting the Unpacking.
  33. >
  34. >What I want to do is to unpack each 'field' of a type short with 
  35. >the data as follows:
  36. >
  37. >Identification        Job Type    Gender
  38. >==============        ========    ======
  39. >bbbbbbbbb        bbbbbb        b
  40. >
  41. >and then be able to read the returned bits and conver them back 
  42. >to their original 'readable' form.
  43. >
  44. >Can someone help me with some code so I can at least see how 
  45. this 
  46. >would be done and maybe understand it then?
  47. >
  48. >What I have so far is listed below and thanks for your 
  49. >assistance in advance.
  50. >
  51. >Mike
  52. >
  53. >
  54. >= = = = = = = = = = 
  55. >
  56. >#include <stdio.h>
  57. >#include <limits.h>
  58. >
  59. >short    create_employee_data(int, int, char);
  60. >void    bit_print(int);
  61. >short    unpak(int, int);
  62. >
  63. >main()
  64. >{
  65. >    int    id_no = 255;
  66. >    int    job_type = 63;
  67. >    char    gender    = 'F';
  68. >    short   employee;
  69. >
  70. >    employee = create_employee_data(id_no,
  71. >                    job_type,
  72. >                    gender);
  73. >    bit_print(employee);
  74.  
  75. -------------------------------------------------------------------
  76. Michael D. Perry      |   FIRST RULE OF INTELLIGENT TINKERING:
  77. MIKA Systems          |       Save all the parts.
  78. Glen Ellyn, Illinois    |   SATTINGER'S LAW:
  79. mdp@mika-sys.com |       It works better if you plug it in.
  80. -------------------------------------------------------------------
  81.